//
//  EmojiEmotion.m
//  YunShouHu
//
//  Created by WangQiang on 16/6/23.
//  Copyright © 2016年 WangQiang. All rights reserved.
//

#import "EmojiEmotion.h"

@implementation EmojiEmotion

static NSArray *_emojis;
-(instancetype)initWithDict:(NSDictionary *)dict{
    if(self = [super init]){
        [self setValuesForKeysWithDictionary:dict];
        self.pngName = [self.pngName stringByAppendingPathExtension:@"png"];
    }
    return self;
}
//-(CGSize)size{
//    return CGSizeMake(25, 25);
//}
+(instancetype)emojiWithDict:(NSDictionary *)dict{
    if(![dict isKindOfClass:[NSDictionary class]]) return [[self alloc] init];
    return [[self alloc] initWithDict:dict];
}
+(NSArray *)emojisWithArray:(NSArray *)emojis{
    if(![emojis isKindOfClass:[NSArray class]]) return [NSArray array];
    NSMutableArray *returnEmojis = [NSMutableArray array];
    for (NSDictionary *dic in emojis) {
        [returnEmojis addObject:[self emojiWithDict:dic]];
    }
    return  returnEmojis;
}
+(NSArray *)allEmojiEmotion{
    if(!_emojis){
        
        _emojis = [self emojisWithArray:[[NSArray alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"Emoji.plist"ofType:nil]]];
    }
    return _emojis;
}
+(instancetype)deleteEmoji{
    EmojiEmotion *delteEmoji = [[EmojiEmotion alloc] init];
    delteEmoji.emojiEncoded = NSLocalizedString(@"删除", nil);
    delteEmoji.pngName = @"face_del_ico_dafeult";
    return delteEmoji;
}
+(instancetype)emojiEmotionWithEncode:(NSString *)encode{
    if(!encode || ![encode isKindOfClass:[NSString class]] || encode.length <= 0) return nil;
    __block EmojiEmotion *emoji;
    [[self allEmojiEmotion] enumerateObjectsUsingBlock:^(EmojiEmotion * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        if([obj.emojiEncoded isEqualToString:encode]){
            emoji = obj;
            *stop = YES;
        }
    }];
    
//    if(!emoji) emoji = [[EmojiEmotion alloc] init];
    return emoji;
}
//
//+(NSArray *)allEmojiEmotion{
//   NSURL * url = [[NSBundle mainBundle] URLForResource:@"emoji" withExtension:nil];
//    NSData *data = [NSData dataWithContentsOfURL:url];
//    NSString *str = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
//    NSArray *results = [str componentsSeparatedByString:@"\r\n"];
//    NSMutableArray *plists = [NSMutableArray array];
//    
//    for (NSString *tempStr in results) {
//        NSMutableDictionary *item = [NSMutableDictionary dictionary];
//        NSArray *comperateStr = [tempStr componentsSeparatedByString:@","];
//        [item setValue:[comperateStr lastObject] forKey:@"emojiEncoded"];
//        [item setValue:[[comperateStr firstObject] stringByReplacingOccurrencesOfString:@".png" withString:@""] forKey:@"pngName"];
////        [item setValue:[NSValue valueWithCGSize:CGSizeMake(30, 30)] forKey:@"size"];
//        [plists addObject:item];
//    }
//    NSString *path = [[[NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject] stringByAppendingPathComponent:@"MyCache"] stringByAppendingPathComponent:@"data.plist"];
//    [plists writeToFile:path atomically:YES];
//    
//  
//    
//    return [NSArray array];
//}
@end
